/*****Log*****/
clear
cd "C:\Users\Joshua\Dropbox\Work\Networks and Economic Perceptions\Data and Do Files"
	/*the above needs to be updated to where you have the data/do files*/
	
log using "Figure 2 and Table 1 Output.smcl", replace
	/*the log file is in format .smcl, but can be read via txt editor*/

set more off

/***********************************************************************
************************************************************************
************************************************************************
This do file contains the needed to replicate our Figure 2 and 
Table 1. This do file also contains the code for the analyses 
presented in Tables OA4 (five point scales) and Tables OA5 
(Fall 2008). 

For each survey, the code will load and clean the data at hand using the
commands included in the survey cleaning .do files and then do the 
analyses in question. For those wishing to use this to replicate the analyses, 
you will need to update the cd command below to point to where your data
and .do files are located. 

Also note that there are two STATA modules that need to be intalled: 
(1) esttab and (2) grc1leg. 

ssc install estout, replace
ssc install grc1leg, replace

Note: The analyses here were run using STATA 13. Users of STATA 15 
will likely get an error message when the esstab 
command below runs, specifically: 
	"equation / not found"
This is because of the "rename" function in the command seems to be 
broken in STATA 15. Deleting this line will fix matters. 


************************************************************************
************************************************************************
***********************************************************************/



/****************************************
*****************************************
		1992 CNEP
*****************************************
****************************************/	

*data cleaning*
do "Data Cleaning - 1992 CNEP.do"
set more off
summ disagree_total, detail
	*5pct -4
	*95pct 3
	
	
/****Bivariate****/
tab retro
tab retro partisan, col chi2



/****Multivariate****/
	
	
eststo clear	

eststo: ologit retro i.partisan##c.disagree_total numgiven disc_knowl news_att age educ ///
	income i.gender i.race i.employed i.marital 
	
margins partisan, at(disagree_total=(-5(1)5)) predict(outcome(3)) 
		marginsplot, scheme(s1mono) xline(-4, lpattern(dot)) xline(3, lpattern(dot)) ///
			title("1992 CNEP" "Pr(Better)") xtitle("") ytitle("") 		
			
			graph save "1992 - Better", replace

margins partisan, at(disagree_total=(-5(1)5)) predict(outcome(3)) 
		marginsplot, scheme(s1mono) xline(-4, lpattern(dot)) xline(3, lpattern(dot)) ///
			title("1992 CNEP" "Pr(Better)") xtitle("") ytitle("") ylabel(0(0.2)1)	///
			text(0.30 4 "In: b= 0.002, z=1.00" ///
				 0.25 4 "Out: b= -0.01, z= -2.44", just(right) size(vsmall))

			graph save "1992 - Better - with text", replace		
			

/****************************************
*****************************************
		2000 ANES
*****************************************
****************************************/	
/***2000***/

clear
do "Data Cleaning - 2000 ANES.do"

set more off
summ disagree_total, detail
	*5pct -4
	*95 pct 2
	
/***Bivariate***/
tab econ_post3 
tab econ_post3 partisan, col chi2
	

eststo: ologit econ_post3 i.partisan##c.disagree_total names1 disc_knowl interest age educ income ///
	i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V000002a]
	
		margins partisan, at(disagree_total=(-4(1)4)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2000 ANES" "Pr(Better)") ///
			ytitle("") xtitle("") xline(-4, lpattern(dot)) xline(2, lpattern(dot)) 
		
		graph save "2000 - Better", replace
			
			
		margins partisan, at(disagree_total=(-4(1)4)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2000 ANES" "Pr(Better)") ylabel(0(0.2)1) ///
			ytitle("") xtitle("") xline(-4, lpattern(dot)) xline(2, lpattern(dot)) ///
			text(0.34 -3 "In: b= 0.03, z= 1.88" ///
				 0.30 -3 "Out: b= -0.01, z = -0.41", just(left) size(vsmall))
				 
		graph save "2000 - Better - with text", replace
			 
			 
/****************************************
*****************************************
		2002 ANES
*****************************************
****************************************/				 
		
*data cleaning
clear
do "Data Cleaning - 2002 ANES.do"


summ disagree_total, detail
	*5pct: -4
	*95: 2
	
	
/**bivariate***/
tab retro2002_3
tab retro2002_3 partisan2000, col chi2


/**multivariate***/	

eststo: ologit retro2002_3 i.partisan2000##c.disagree_total names1 disc_knowl ///
	follow age2002 educ income2002 i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight=WT02PRE]
		
		margins partisan2000, at(disagree_total=(-4(1)4)) predict(outcome(3)) 
		marginsplot, scheme(s1mono) title("2002 ANES" "Pr(Better)") ///
			ytitle("") xtitle("") xline(-4, lpattern(dot)) xline(2, lpattern(dot)) 
		
		graph save "2002 - Better", replace
		
		margins partisan2000, at(disagree_total=(-4(1)4)) predict(outcome(3)) 
		marginsplot, scheme(s1mono) title("2002 ANES" "Pr(Better)") ylabel(0(0.2)1) ///
			ytitle("") xtitle("") xline(-4, lpattern(dot)) xline(2, lpattern(dot)) ///
			text(0.14 -3 "In: b= -0.003, z = -0.17" ///
				 0.10 -3 "Out: b= -0.001, z = -0.05", just(left) size(vsmall))
	
		graph save "2002 - Better - with text", replace

/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/	

*data cleaning
clear
do "Data Cleaning - 2006 ANES.do"
set more off

/****Bivariate***/

tab retro
tab retro partisan2004, col chi2

/****multivariate***/


summ disagree_total, detail
	*5pt: -3
	*95: 1

eststo: ologit retro i.partisan2004##c.disagree_total names disc_interest follow04 ///
	age educ income i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V06P002]	
	
		margins partisan2004, at(disagree_total=(-3(1)3)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2006 ANES" "Pr(Better)") ///
		ytitle("") xtitle("") xline(-3, lpattern(dot)) xline(1, lpattern(dot)) 
		
		graph save "2006 - Better" , replace
		
		margins partisan2004, at(disagree_total=(-3(1)3)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2006 ANES" "Pr(Better)") ylabel(0(0.2)1) ///
		ytitle("") xtitle("") xline(-3, lpattern(dot)) xline(1, lpattern(dot)) ///
		text(0.65 2 "In: b = -0.06, z = -2.82" ///
			 0.60 2 "out: b = -0.003, z = -0.21", just(right) size(vsmall))
			 
		graph save "2006 - Better - with text" , replace

		
/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/	

clear
do "Data Cleaning - 2008 Panel.do"
set more off


/****bivariate****/

tab w17_retro
tab w17_retro partisan_9rev, col chi2

tab w19_retro
tab w19_retro partisan_9rev, col chi2

/****multivariate****/

summ disagree_total, detail
	*5: -3
	*95: 3


eststo: ologit w17_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
	
		margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2008-2009 ANES (May)" "Pr(Better)") ///
			xtitle("") ytitle("") xline(-3, lpattern(dot)) xline(3, lpattern(dot))
			
		graph save "May - Better" , replace
		
		margins, dydx(disagree_total) by(partisan_9rev) predict(outcome(3))
		
		margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2008-2009 ANES (May)" "Pr(Better)") ylabel(0(0.2)1) ///
			xtitle("") ytitle("") xline(-3, lpattern(dot)) xline(3, lpattern(dot)) ///
			text(0.4 -2 "In: b= -0.01, z = -1.13" ///
				 0.35 -2 "Out: b = 0.003, z = 0.65", just(left) size(vsmall))
				 
		graph save "May - Better - with text (updated)" , replace


		
eststo: ologit w19_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]
	
		margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2008-2009 ANES (July)" "Pr(Better)") ///
			xtitle("") ytitle("") xline(-3, lpattern(dot)) xline(3, lpattern(dot)) 
			
		graph save "July - Better" , replace	
		
		margins, dydx(disagree_total) by(partisan_9rev) predict(outcome(3))
		
		margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3))
		marginsplot, scheme(s1mono) title("2008-2009 ANES (July)" "Pr(Better)") ///
			xtitle("") ytitle("") xline(-3, lpattern(dot)) xline(3, lpattern(dot)) ylabel(0(0.2)1) ///
			text(0.35 -2 "In: b= -0.005, z = -0.65" ///
				 0.30 -2 "Out: b= 0.005, z = 1.38", just(left) size(vsmall))
		
		graph save "July - Better - with text (updated)" , replace	
	
		

/**Table**/
esttab using TABLEOA7_ECON3.rtf, onecell replace nobaselevels label se pr2 aic bic ///
	star(+ 0.10 * 0.05 ** 0.01) ///
	rename(1.partisan In-Partisan 1.partisan2000 In-Partisan ///
		1.partisan2006 In-Partisan 1.partisan_9rev In-Partisan) ///
 	mtitles("1992 CNEP" "2000 ANES" "2002 ANES" "2006 ANES" "2008-2009 Panel (May)" ///
		"2008-2009 Panel (July)") ///
	title({\b Table OA7.} "Network Disagreement & Economic Evaluations") ///
	addnote("ANES results are weighted.") 
	
/**Figure**/

grc1leg "1992 - Better" "2000 - Better" "2002 - Better" "2006 - Better" ///
"May - Better" "July - Better"  , scheme(s1mono) ycommon


graph save "Figure 3 - Evals", replace
graph export "Figure 3 - Evals.png", replace
graph export "Figure 3 - Evals.tif", replace



grc1leg "1992 - Better - with text" "2000 - Better - with text" "2002 - Better - with text" "2006 - Better - with text" ///
"May - Better - with text (updated)" "July - Better - with text (updated)"  , scheme(s1mono) ycommon

	/*the combination process displaces the correct placement of the added text, so I 
	rearranged the text boxes for the in/out partisan effects manually.*/


	
	
/****************************************
*****************************************
		Table OA4
		3 vs 5 pt 
*****************************************
****************************************/	

clear
eststo clear
/**2000**/
do "Data Cleaning - 2000 ANES.do"

eststo: ologit econ_post3 i.partisan##c.disagree_total names1 disc_knowl interest age educ income ///
	i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V000002a]

eststo: ologit econ_post5 i.partisan##c.disagree_total names1 disc_knowl interest age educ income ///
	i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V000002a]

	
/**2002**/
clear
do "Data Cleaning - 2002 ANES.do"
set more off

eststo: ologit retro2002_3 i.partisan2000##c.disagree_total names1 disc_knowl ///
	follow age2002 educ income2002 i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight=WT02PRE]
eststo: ologit retro2002 i.partisan2000##c.disagree_total names1 disc_knowl ///
	follow age2002 educ income2002 i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight=WT02PRE]

	
	
/**2008-2009**/
clear 

do "Data Cleaning - 2008 Panel.do"
set more off

eststo: ologit w17_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
eststo: ologit w17_retro5 i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
eststo: ologit w19_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]
eststo: ologit w19_retro5 i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]
		
/**Table**/

esttab using TABLEOA8_3VS5.rtf, replace nobaselevels onecell label se pr2 aic bic ///
	star(+ 0.10 * .05 ** 0.01) ///
	mtitles("2000:3pt" "2000:5pt" "2002:3pt" "2002:5pt" "May 2009:3pt" ///
	"May 2009:5pt" "July 2009:3pt" "July 2009:5pt") ///
	addnote("ANES results are weighted.") ///
	rename(1.partisan Co-Partisanship 1.partisan2000 Co-Partisanship 1.partisan_9rev Co-Partisanship)
	

	
	
/****************************************
*****************************************
		Table OA5
		Fall 2008 Analyses 
*****************************************
****************************************/


clear 
do "Data Cleaning - 2008 Panel.do"
set more off


eststo clear
eststo: ologit w10_retro i.partisan_9 c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.empl_cp1 i.race  i.marital nfc1 evaluate1 [pweight= WGTL10]
	
eststo: ologit w10_retro i.partisan_9##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.empl_cp1 i.race  i.marital nfc1 evaluate1 [pweight= WGTL10]
	
eststo: ologit w11_retro i.partisan_9 c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.empl_cp1 i.race i.marital nfc1 evaluate1 [pweight= WGTL11]
		
eststo: ologit w11_retro i.partisan_9##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.empl_cp1 i.race i.marital nfc1 evaluate1 [pweight= WGTL11]
		
		margins partisan_9,  at(disagree_total=(-3(1)3)) predict(outcome(1))
		marginsplot, scheme(s1mono) title("Nov. 2008" "Prob(Worse)") ytitle("") ///
			xline(-3, lpattern(dot)) xline(3, lpattern(dot))
		
		
		graph save "Nov. 2008 (updated)", replace
		graph export "Nov. 2008 (updated).png", replace
		
	
esttab using MODERATION_FALL.rtf, replace nobaselevels onecell label se pr2 aic bic ///
	star(+ 0.10 * .05 ** 0.01) ///
	mtitles("Oct. 2008" "Oct. 2008" "Nov. 2008" "Nov. 2008") ///
	addnote("ANES results are weighted: WGTL10 & WGTL11") ///
	title({\b Table OA9.} "Network Disagreement and Economic Assessments - Fall 2008") 



log close

